{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[01;34m/home/njuciairs/wangshuai/competitions/finance_features/\u001b[00m\r\n",
      "├── \u001b[01;34mBertSentiEntity_cross\u001b[00m\r\n",
      "│   ├── feature_split 1\r\n",
      "│   ├── feature_split 2\r\n",
      "│   ├── feature_split 3\r\n",
      "│   ├── feature_split 4\r\n",
      "│   ├── feature_split 5\r\n",
      "│   ├── feature_split 6\r\n",
      "│   ├── feature_split 7\r\n",
      "│   ├── feature_split 8\r\n",
      "│   ├── feature_split 9\r\n",
      "│   ├── test_features_version 1\r\n",
      "│   ├── test_features_version 2\r\n",
      "│   ├── test_features_version 3\r\n",
      "│   ├── test_features_version 4\r\n",
      "│   ├── test_features_version 5\r\n",
      "│   ├── test_features_version 6\r\n",
      "│   ├── test_features_version 7\r\n",
      "│   ├── test_features_version 8\r\n",
      "│   ├── test_features_version 9\r\n",
      "│   ├── test_features_version_goodremove 1\r\n",
      "│   ├── test_features_version_goodremove 2\r\n",
      "│   ├── test_features_version_goodremove 3\r\n",
      "│   ├── test_features_version_goodremove 4\r\n",
      "│   ├── test_features_version_goodremove 5\r\n",
      "│   ├── test_features_version_goodremove 6\r\n",
      "│   ├── test_features_version_goodremove 7\r\n",
      "│   ├── test_features_version_goodremove 8\r\n",
      "│   └── test_features_version_goodremove 9\r\n",
      "├── \u001b[01;34mmulti_class_cross1\u001b[00m\r\n",
      "│   ├── feature_split 1\r\n",
      "│   ├── feature_split 2\r\n",
      "│   ├── feature_split 3\r\n",
      "│   ├── feature_split 4\r\n",
      "│   ├── feature_split 5\r\n",
      "│   ├── feature_split 6\r\n",
      "│   ├── feature_split 7\r\n",
      "│   ├── feature_split 8\r\n",
      "│   ├── feature_split 9\r\n",
      "│   ├── test_features_version 1\r\n",
      "│   ├── test_features_version 2\r\n",
      "│   ├── test_features_version 3\r\n",
      "│   ├── test_features_version 4\r\n",
      "│   ├── test_features_version 5\r\n",
      "│   ├── test_features_version 6\r\n",
      "│   ├── test_features_version 7\r\n",
      "│   ├── test_features_version 8\r\n",
      "│   └── test_features_version 9\r\n",
      "├── \u001b[01;34mmulti_class_cross_roberta\u001b[00m\r\n",
      "│   ├── feature_split 1\r\n",
      "│   ├── feature_split 2\r\n",
      "│   ├── feature_split 3\r\n",
      "│   ├── feature_split 4\r\n",
      "│   ├── feature_split 5\r\n",
      "│   ├── feature_split 6\r\n",
      "│   ├── feature_split 7\r\n",
      "│   ├── feature_split 8\r\n",
      "│   ├── feature_split 9\r\n",
      "│   ├── test_features_version 1\r\n",
      "│   ├── test_features_version 2\r\n",
      "│   ├── test_features_version 3\r\n",
      "│   ├── test_features_version 4\r\n",
      "│   ├── test_features_version 5\r\n",
      "│   ├── test_features_version 6\r\n",
      "│   ├── test_features_version 7\r\n",
      "│   ├── test_features_version 8\r\n",
      "│   └── test_features_version 9\r\n",
      "└── \u001b[01;34mpredict_features\u001b[00m\r\n",
      "    ├── mc_rb.csv\r\n",
      "    ├── mc_rb_se.csv\r\n",
      "    ├── mc_rb_se_test.csv\r\n",
      "    ├── mc_rb_test.csv\r\n",
      "    └── rc_rb.csv\r\n",
      "\r\n",
      "4 directories, 68 files\r\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "os.chdir('../')\n",
    "from config import conf\n",
    "import pandas as pd\n",
    "import os\n",
    "from os.path import join\n",
    "import re\n",
    "import numpy as np\n",
    "FEATURE_ROOT_DIR = conf.get('linux_dir', 'feature_root_dir')\n",
    "!tree $FEATURE_ROOT_DIR"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>title</th>\n",
       "      <th>text</th>\n",
       "      <th>entity</th>\n",
       "      <th>negative</th>\n",
       "      <th>key_entity</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>83dcefb7</td>\n",
       "      <td>????发表了博文《【富金利】9月富金利教你如何安全提高最大化收益！》网络理财时代参与互联网...</td>\n",
       "      <td>????发表了博文《【富金利】9月富金利教你如何安全提高最大化收益！》网络理财时代参与互联网...</td>\n",
       "      <td>理财时代;富金利</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>1ad5be0d</td>\n",
       "      <td>#小资钱包涉嫌诈骗[超话]##小资钱包[超话]##迫切急待回归活命钱##头号直通中纪委[超话...</td>\n",
       "      <td>#小资钱包涉嫌诈骗[超话]##小资钱包[超话]##迫切急待回归活命钱##头号直通中纪委[超话...</td>\n",
       "      <td>小资钱包;恒丰银行</td>\n",
       "      <td>1</td>\n",
       "      <td>小资钱包;恒丰银行</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>6dd28e9b</td>\n",
       "      <td>?????扫黑除恶 诈骗犯齐聚海淀，保护伞根深蒂固，黑社会嚣张跋扈，出借人走投无路！ 尊敬的...</td>\n",
       "      <td>?????扫黑除恶 诈骗犯齐聚海淀，保护伞根深蒂固，黑社会嚣张跋扈，出借人走投无路！ 尊敬的...</td>\n",
       "      <td>国有投资;资易贷（北京）金融信息服务有限公司;小资钱包;资易贷</td>\n",
       "      <td>1</td>\n",
       "      <td>资易贷（北京）金融信息服务有限公司;小资钱包</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>1db87a14</td>\n",
       "      <td>平安银行车主贷?????? 1??期限长至48期?? 2??滴滴司机可做?? 3??白户逾期...</td>\n",
       "      <td>平安银行车主贷?????? 1??期限长至48期?? 2??滴滴司机可做?? 3??白户逾期...</td>\n",
       "      <td>平安银行;车主贷;平安银行车主贷</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>fa005713</td>\n",
       "      <td>NaN</td>\n",
       "      <td>旺旺贷跑路！深圳警方确定投资人被骗！</td>\n",
       "      <td>旺贷;旺旺贷</td>\n",
       "      <td>1</td>\n",
       "      <td>旺旺贷</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         id                                              title  \\\n",
       "0  83dcefb7  ????发表了博文《【富金利】9月富金利教你如何安全提高最大化收益！》网络理财时代参与互联网...   \n",
       "1  1ad5be0d  #小资钱包涉嫌诈骗[超话]##小资钱包[超话]##迫切急待回归活命钱##头号直通中纪委[超话...   \n",
       "2  6dd28e9b  ?????扫黑除恶 诈骗犯齐聚海淀，保护伞根深蒂固，黑社会嚣张跋扈，出借人走投无路！ 尊敬的...   \n",
       "3  1db87a14  平安银行车主贷?????? 1??期限长至48期?? 2??滴滴司机可做?? 3??白户逾期...   \n",
       "4  fa005713                                                NaN   \n",
       "\n",
       "                                                text  \\\n",
       "0  ????发表了博文《【富金利】9月富金利教你如何安全提高最大化收益！》网络理财时代参与互联网...   \n",
       "1  #小资钱包涉嫌诈骗[超话]##小资钱包[超话]##迫切急待回归活命钱##头号直通中纪委[超话...   \n",
       "2  ?????扫黑除恶 诈骗犯齐聚海淀，保护伞根深蒂固，黑社会嚣张跋扈，出借人走投无路！ 尊敬的...   \n",
       "3  平安银行车主贷?????? 1??期限长至48期?? 2??滴滴司机可做?? 3??白户逾期...   \n",
       "4                                 旺旺贷跑路！深圳警方确定投资人被骗！   \n",
       "\n",
       "                            entity  negative              key_entity  \n",
       "0                         理财时代;富金利         0                     NaN  \n",
       "1                        小资钱包;恒丰银行         1               小资钱包;恒丰银行  \n",
       "2  国有投资;资易贷（北京）金融信息服务有限公司;小资钱包;资易贷         1  资易贷（北京）金融信息服务有限公司;小资钱包  \n",
       "3                 平安银行;车主贷;平安银行车主贷         0                     NaN  \n",
       "4                           旺贷;旺旺贷         1                     旺旺贷  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from data_utils.basic_data import load_basic_dataset\n",
    "from functools import reduce\n",
    "train_df = load_basic_dataset('train')\n",
    "train_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# def get_label(id,entity):  \n",
    "#     return int(str(entity).strip() in str(train_df[train_df['id']==id]['key_entity'].values[0]).split(';'))\n",
    "# def get_senti_label(id):  \n",
    "#     return train_df[train_df['id']==id]['negative'].values[0]\n",
    "# feature_df = pd.read_csv(join(FEATURE_ROOT_DIR,'predict_features','mc_rb_se.csv'))\n",
    "# feature_df['label'] = feature_df[['id','entity']].apply(lambda x:get_label(x[0],x[1]),axis=1)\n",
    "# feature_df['senti_label'] = feature_df['id'].map(get_senti_label)\n",
    "# feature_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def load_feature_df():\n",
    "    def get_label(id,entity):  \n",
    "        return int(str(entity).strip() in str(train_df[train_df['id']==id]['key_entity'].values[0]).split(';'))\n",
    "    def get_senti_label(id):  \n",
    "        return train_df[train_df['id']==id]['negative'].values[0]\n",
    "    feature_df = pd.read_csv(join(FEATURE_ROOT_DIR,'predict_features','mc_rb_se.csv'))\n",
    "    feature_df['label'] = feature_df[['id','entity']].apply(lambda x:get_label(x[0],x[1]),axis=1)\n",
    "    feature_df['senti_label'] = feature_df['id'].map(get_senti_label)\n",
    "    feature_df = feature_df.dropna()\n",
    "    for c in ['mc_predict', 'rb_predict', 'se_entity', 'se_sentence']:\n",
    "        feature_df[c] = feature_df[c].map(lambda x:eval(x))\n",
    "    return feature_df\n",
    "def load_test_feature_df():\n",
    "    feature_df = pd.read_csv(join(FEATURE_ROOT_DIR,'predict_features','mc_rb_se_test.csv'))\n",
    "    feature_df = feature_df[feature_df['se_entity'].map(lambda x:isinstance(x,str))]\n",
    "    for c in ['mc_predict', 'rb_predict', 'se_entity', 'se_sentence']:\n",
    "        feature_df[c] = feature_df[c].map(lambda x:eval(x))\n",
    "    return feature_df\n",
    "# feature_df.head(10)\n",
    "# feature_df = load_test_feature_df()\n",
    "# feature_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "feature_df = load_feature_df()\n",
    "features = list(map(lambda x:reduce(lambda y,z:y+z,x),feature_df[['mc_predict', 'rb_predict', 'se_entity', 'se_sentence']].values))\n",
    "labels = feature_df['label'].values\n",
    "test_feature_df = load_test_feature_df()\n",
    "test_features = list(map(lambda x:reduce(lambda y,z:y+z,x),test_feature_df[['mc_predict', 'rb_predict', 'se_entity', 'se_sentence']].values))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4.715544610736523e-17\n",
      "0.9999999999999974\n",
      "0.93\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "      Benign       0.93      0.95      0.94        56\n",
      "   Malignant       0.93      0.91      0.92        44\n",
      "\n",
      "    accuracy                           0.93       100\n",
      "   macro avg       0.93      0.93      0.93       100\n",
      "weighted avg       0.93      0.93      0.93       100\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/njuciairs/anaconda3/envs/tftorch/lib/python3.6/site-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.\n",
      "  FutureWarning)\n"
     ]
    }
   ],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "#拆分训练集和测试集（train_test_split是存在与sklearn中的函数）\n",
    "X_train,X_test,y_train,y_test = train_test_split(features,labels,train_size=0.99)\n",
    "#train为训练数据,test为测试数据,examDf为源数据,train_size 规定了训练数据的占比\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "sc = StandardScaler()\n",
    "sc.fit(X_train)\n",
    "X_train_std = sc.transform(X_train)\n",
    "X_test_std = sc.transform(X_test)\n",
    "x_inferece_std = sc.transform(test_features)\n",
    "\n",
    "print (np.mean(X_train_std))\n",
    "print (np.var(X_train_std))\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "#from sklearn.ensemble import  AdaBoostClassifier as LogisticRegression\n",
    "lr = LogisticRegression()\n",
    "lr.fit(X_train_std,y_train)\n",
    "from sklearn.metrics import *\n",
    "print(lr.score(X_test_std,y_test))\n",
    "y_result = lr.predict(X_test_std)\n",
    "print(classification_report(y_test,y_result,target_names=['Benign','Malignant']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_inferece = lr.predict(x_inferece_std)\n",
    "test_feature_df['entity_label'] = y_inferece.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>entity</th>\n",
       "      <th>mc_predict</th>\n",
       "      <th>rb_predict</th>\n",
       "      <th>se_entity</th>\n",
       "      <th>se_sentence</th>\n",
       "      <th>entity_label</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>11588</td>\n",
       "      <td>fff09e68</td>\n",
       "      <td>微贷网</td>\n",
       "      <td>[6.037400000000001, -3.467222222222222, -1.707...</td>\n",
       "      <td>[6.806388888888889, -3.465666666666667, -2.436...</td>\n",
       "      <td>[0.6003560953670077, -0.22535289306607512]</td>\n",
       "      <td>[-2.606042093700833, 2.762931307156881]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11589</td>\n",
       "      <td>fff09e68</td>\n",
       "      <td>极光金融</td>\n",
       "      <td>[5.917733333333334, -3.083188888888889, -1.854...</td>\n",
       "      <td>[6.2386, -3.2515333333333327, -2.2451444444444...</td>\n",
       "      <td>[2.133933130237791, -1.8542762166923947]</td>\n",
       "      <td>[-2.606042093700833, 2.762931307156881]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11590</td>\n",
       "      <td>fff09e68</td>\n",
       "      <td>爱钱进</td>\n",
       "      <td>[5.311633333333333, -2.9932777777777777, -1.42...</td>\n",
       "      <td>[6.257655555555555, -3.4496777777777776, -1.96...</td>\n",
       "      <td>[-1.8290556834803686, 2.0096324872639446]</td>\n",
       "      <td>[-2.606042093700833, 2.762931307156881]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11591</td>\n",
       "      <td>fff09e68</td>\n",
       "      <td>翼龙贷</td>\n",
       "      <td>[3.648866666666667, -3.383777777777778, 0.4199...</td>\n",
       "      <td>[4.536222222222222, -3.4316888888888886, -0.73...</td>\n",
       "      <td>[-0.4364754855632782, 0.7403760486178927]</td>\n",
       "      <td>[-2.606042093700833, 2.762931307156881]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11592</td>\n",
       "      <td>fff09e68</td>\n",
       "      <td>觅宝网</td>\n",
       "      <td>[4.018833333333333, -2.7274, -0.5852555555555556]</td>\n",
       "      <td>[5.4155, -3.182322222222222, -1.6177777777777778]</td>\n",
       "      <td>[-1.7555922617514927, 1.879330162372854]</td>\n",
       "      <td>[-2.606042093700833, 2.762931307156881]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             id entity                                         mc_predict  \\\n",
       "11588  fff09e68    微贷网  [6.037400000000001, -3.467222222222222, -1.707...   \n",
       "11589  fff09e68   极光金融  [5.917733333333334, -3.083188888888889, -1.854...   \n",
       "11590  fff09e68    爱钱进  [5.311633333333333, -2.9932777777777777, -1.42...   \n",
       "11591  fff09e68    翼龙贷  [3.648866666666667, -3.383777777777778, 0.4199...   \n",
       "11592  fff09e68    觅宝网  [4.018833333333333, -2.7274, -0.5852555555555556]   \n",
       "\n",
       "                                              rb_predict  \\\n",
       "11588  [6.806388888888889, -3.465666666666667, -2.436...   \n",
       "11589  [6.2386, -3.2515333333333327, -2.2451444444444...   \n",
       "11590  [6.257655555555555, -3.4496777777777776, -1.96...   \n",
       "11591  [4.536222222222222, -3.4316888888888886, -0.73...   \n",
       "11592  [5.4155, -3.182322222222222, -1.6177777777777778]   \n",
       "\n",
       "                                        se_entity  \\\n",
       "11588  [0.6003560953670077, -0.22535289306607512]   \n",
       "11589    [2.133933130237791, -1.8542762166923947]   \n",
       "11590   [-1.8290556834803686, 2.0096324872639446]   \n",
       "11591   [-0.4364754855632782, 0.7403760486178927]   \n",
       "11592    [-1.7555922617514927, 1.879330162372854]   \n",
       "\n",
       "                                   se_sentence  entity_label  \n",
       "11588  [-2.606042093700833, 2.762931307156881]             0  \n",
       "11589  [-2.606042093700833, 2.762931307156881]             0  \n",
       "11590  [-2.606042093700833, 2.762931307156881]             0  \n",
       "11591  [-2.606042093700833, 2.762931307156881]             0  \n",
       "11592  [-2.606042093700833, 2.762931307156881]             0  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_feature_df[test_feature_df['id']=='fff09e68']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# tdf = load_basic_dataset('test')\n",
    "# tdf[tdf['id']=='fff09e68']['text'].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "senti_labels = feature_df['senti_label'].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5.8594090642437155e-05\n",
      "1.000326928093834\n",
      "0.98\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "      Benign       1.00      0.95      0.98        43\n",
      "   Malignant       0.97      1.00      0.98        57\n",
      "\n",
      "    accuracy                           0.98       100\n",
      "   macro avg       0.98      0.98      0.98       100\n",
      "weighted avg       0.98      0.98      0.98       100\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/njuciairs/anaconda3/envs/tftorch/lib/python3.6/site-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.\n",
      "  FutureWarning)\n"
     ]
    }
   ],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "#拆分训练集和测试集（train_test_split是存在与sklearn中的函数）\n",
    "X_train,X_test,y_train,y_test = train_test_split(features,senti_labels,train_size=0.99)\n",
    "#train为训练数据,test为测试数据,examDf为源数据,train_size 规定了训练数据的占比\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "X_train_std = sc.transform(X_train)\n",
    "X_test_std = sc.transform(X_test)\n",
    "x_inferece_std = sc.transform(test_features)\n",
    "\n",
    "print (np.mean(X_train_std))\n",
    "print (np.var(X_train_std))\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "#from sklearn.ensemble import  AdaBoostClassifier as LogisticRegression\n",
    "\n",
    "lr = LogisticRegression()\n",
    "lr.fit(X_train_std,y_train)\n",
    "from sklearn.metrics import *\n",
    "print(lr.score(X_test_std,y_test))\n",
    "y_result = lr.predict(X_test_std)\n",
    "print(classification_report(y_test,y_result,target_names=['Benign','Malignant']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_inferece = lr.predict(x_inferece_std)\n",
    "test_feature_df['senti_label'] = y_inferece.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>entity</th>\n",
       "      <th>senti_label</th>\n",
       "      <th>entity_label</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>00049297</td>\n",
       "      <td>小资钱包</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>00049297</td>\n",
       "      <td>资易贷金融信息服务有限公司</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>000b8b75</td>\n",
       "      <td>京东白条</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>0012d20a</td>\n",
       "      <td>国际微交易</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>0012d20a</td>\n",
       "      <td>微交易</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11590</td>\n",
       "      <td>fff09e68</td>\n",
       "      <td>爱钱进</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11591</td>\n",
       "      <td>fff09e68</td>\n",
       "      <td>翼龙贷</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11592</td>\n",
       "      <td>fff09e68</td>\n",
       "      <td>觅宝网</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11593</td>\n",
       "      <td>fffe28dd</td>\n",
       "      <td>金融官网</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11594</td>\n",
       "      <td>fffe28dd</td>\n",
       "      <td>黑火金融</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>10293 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             id         entity  senti_label  entity_label\n",
       "0      00049297           小资钱包            1             1\n",
       "2      00049297  资易贷金融信息服务有限公司            1             1\n",
       "3      000b8b75           京东白条            0             0\n",
       "4      0012d20a          国际微交易            0             0\n",
       "5      0012d20a            微交易            0             0\n",
       "...         ...            ...          ...           ...\n",
       "11590  fff09e68            爱钱进            0             0\n",
       "11591  fff09e68            翼龙贷            0             0\n",
       "11592  fff09e68            觅宝网            0             0\n",
       "11593  fffe28dd           金融官网            1             0\n",
       "11594  fffe28dd           黑火金融            1             1\n",
       "\n",
       "[10293 rows x 4 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rs_df = test_feature_df[['id','entity','senti_label','entity_label']]\n",
    "rs_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['id', 'entity', 'senti_label', 'entity_label'], dtype='object')"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rs_df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "rs_dict = {}\n",
    "for id,entity,senti_label,entity_label in rs_df.values:\n",
    "    if id not in rs_dict:\n",
    "        rs_dict[id] = ([],[])#senti,entity\n",
    "    rs_dict[id][0].append(senti_label)\n",
    "    if entity_label == 1:\n",
    "        rs_dict[id][1].append(entity)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "items = []\n",
    "for id,(sentis,entities) in rs_dict.items():\n",
    "    senti = int(np.mean(sentis) >= 0.5)\n",
    "    if len(entities) > 0:\n",
    "        key_entity = ';'.join(entities)\n",
    "    else:\n",
    "        key_entity = np.nan\n",
    "    items.append((id,senti,key_entity))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>negative</th>\n",
       "      <th>key_entity</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>00049297</td>\n",
       "      <td>1</td>\n",
       "      <td>小资钱包;资易贷金融信息服务有限公司</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>000b8b75</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>0012d20a</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>0033ebe3</td>\n",
       "      <td>1</td>\n",
       "      <td>联璧金融</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>003b1540</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4995</td>\n",
       "      <td>ffa46c98</td>\n",
       "      <td>1</td>\n",
       "      <td>小资钱包;资易贷</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4996</td>\n",
       "      <td>ffc0005d</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4997</td>\n",
       "      <td>ffd1497a</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4998</td>\n",
       "      <td>fff09e68</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4999</td>\n",
       "      <td>fffe28dd</td>\n",
       "      <td>1</td>\n",
       "      <td>黑火金融</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5000 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            id  negative          key_entity\n",
       "0     00049297         1  小资钱包;资易贷金融信息服务有限公司\n",
       "1     000b8b75         0                 NaN\n",
       "2     0012d20a         0                 NaN\n",
       "3     0033ebe3         1                联璧金融\n",
       "4     003b1540         0                 NaN\n",
       "...        ...       ...                 ...\n",
       "4995  ffa46c98         1            小资钱包;资易贷\n",
       "4996  ffc0005d         0                 NaN\n",
       "4997  ffd1497a         0                 NaN\n",
       "4998  fff09e68         0                 NaN\n",
       "4999  fffe28dd         1                黑火金融\n",
       "\n",
       "[5000 rows x 3 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rs_df = pd.DataFrame(items,columns=['id','negative','key_entity'])\n",
    "rs_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "both existsed: fbc区块链;fbc区块链期货\n",
      "both existsed: fbc区块链期货;fbc区块链\n",
      "both existsed: 应文投资;上海应文投资管理有限公司\n",
      "both existsed: 上海应文投资管理有限公司;应文投资\n",
      "both existsed: 钱爸爸;深圳市钱爸爸电子商务有限公司\n",
      "both existsed: 深圳市钱爸爸电子商务有限公司;钱爸爸\n",
      "both existsed: 昆明泛亚有色;昆明泛亚有色金属交易所股份有限公司\n",
      "both existsed: 昆明泛亚有色金属交易所股份有限公司;昆明泛亚有色\n",
      "both existsed: 望洲财富投资管理有限公司;望洲财富\n",
      "both existsed: 望洲财富;望洲财富投资管理有限公司\n",
      "both existsed: 鼎信投资;北京中融鼎信投资管理有限公司\n",
      "both existsed: 北京中融鼎信投资管理有限公司;鼎信投资\n",
      "both existsed: 北京资易贷金融信息服务有限公司（简称小资钱包）;小资钱包\n",
      "both existsed: 小资钱包;北京资易贷金融信息服务有限公司（简称小资钱包）\n",
      "both existsed: 钱爸爸;深圳市钱爸爸电子商务有限公司\n",
      "both existsed: 深圳市钱爸爸电子商务有限公司;钱爸爸\n",
      "both existsed: 北京资易贷金融信息服务有限公司（小资钱包）;小资钱包\n",
      "both existsed: 小资钱包;北京资易贷金融信息服务有限公司（小资钱包）\n",
      "both existsed: 北京资易贷金融信息服务有限公司（小资钱包）;小资钱包\n",
      "both existsed: 小资钱包;北京资易贷金融信息服务有限公司（小资钱包）\n",
      "both existsed: 北京资易贷公司（小资钱包平台）;小资钱包\n",
      "both existsed: 小资钱包;北京资易贷公司（小资钱包平台）\n",
      "both existsed: 渤海创投;天津渤海创投集团\n",
      "both existsed: 天津渤海创投集团;渤海创投\n",
      "both existsed: 壹佰金融;深圳市壹佰金融服务有限公司\n",
      "both existsed: 深圳市壹佰金融服务有限公司;壹佰金融\n",
      "both existsed: 上海闵行微积金互联网金融服务(上海)有限公司;微积金\n",
      "both existsed: 微积金;上海闵行微积金互联网金融服务(上海)有限公司\n",
      "both existsed: 资易贷;资易贷（北京）金融服务有限公司\n",
      "both existsed: 资易贷（北京）金融服务有限公司;资易贷\n",
      "both existsed: 深圳荧兴源资产管理集团;荧兴源\n",
      "both existsed: 荧兴源;深圳荧兴源资产管理集团\n",
      "both existsed: 小资钱包;北京资易贷金融信息服务有限公司（简称小资钱包） \n",
      "both existsed: 北京资易贷金融信息服务有限公司（简称小资钱包） ;小资钱包\n",
      "both existsed: 深圳恒富金融集团有限公司;恒富金融\n",
      "both existsed: 恒富金融;深圳恒富金融集团有限公司\n",
      "both existsed: 钱爸爸;深圳市钱爸爸电子商务有限公司\n",
      "both existsed: 深圳市钱爸爸电子商务有限公司;钱爸爸\n",
      "both existsed: 钱爸爸;深圳市钱爸爸电子商务有限公司\n",
      "both existsed: 深圳市钱爸爸电子商务有限公司;钱爸爸\n",
      "both existsed: 泰安市兴泰创富企业管理咨询有限公司;兴泰创富\n",
      "both existsed: 兴泰创富;泰安市兴泰创富企业管理咨询有限公司\n",
      "both existsed: 上海玺鉴金融信息服务有限公司;玺鉴金融\n",
      "both existsed: 玺鉴金融;上海玺鉴金融信息服务有限公司\n",
      "both existsed: 北京资易贷金融信息服务有限公司（简称小资钱包）;小资钱包\n",
      "both existsed: 小资钱包;北京资易贷金融信息服务有限公司（简称小资钱包）\n",
      "both existsed: 钱爸爸;深圳市钱爸爸电子商务有限公司\n",
      "both existsed: 深圳市钱爸爸电子商务有限公司;钱爸爸\n",
      "both existsed: 昆明泛亚有色;昆明泛亚有色金属交易所股份有限公司\n",
      "both existsed: 昆明泛亚有色金属交易所股份有限公司;昆明泛亚有色\n",
      "both existsed: 美信资产;深圳市美信资产管理公司\n",
      "both existsed: 深圳市美信资产管理公司;美信资产\n",
      "both existsed: 深圳市票据宝金融服务有限公司;票据宝\n",
      "both existsed: 票据宝;深圳市票据宝金融服务有限公司\n",
      "both existsed: 深圳前海大福资本管理有限公司;深圳前海大福\n",
      "both existsed: 深圳前海大福;深圳前海大福资本管理有限公司\n",
      "both existsed: 北京资易贷金融信息服务有限公司（小资钱包）;小资钱包\n",
      "both existsed: 小资钱包;北京资易贷金融信息服务有限公司（小资钱包）\n",
      "both existsed: 昆明泛亚有色;昆明泛亚有色金属交易所股份有限公司\n",
      "both existsed: 昆明泛亚有色金属交易所股份有限公司;昆明泛亚有色\n",
      "both existsed: 泛亚有色;泛亚有色金属交易所股份有限公司\n",
      "both existsed: 泛亚有色金属交易所股份有限公司;泛亚有色\n",
      "both existsed: 昆明泛亚有色;昆明泛亚有色金属交易所股份有限公司\n",
      "both existsed: 昆明泛亚有色金属交易所股份有限公司;昆明泛亚有色\n",
      "both existsed: 米袋360;米袋\n",
      "both existsed: 米袋;米袋360\n",
      "both existsed: 北京资易贷金融信息服务有限公司（小资钱包）;小资钱包\n",
      "both existsed: 小资钱包;北京资易贷金融信息服务有限公司（小资钱包）\n",
      "both existsed: 资易贷(小资钱包）;小资钱包\n",
      "both existsed: 小资钱包;资易贷(小资钱包）\n",
      "both existsed: 钱爸爸;深圳市钱爸爸电子商务有限公司\n",
      "both existsed: 深圳市钱爸爸电子商务有限公司;钱爸爸\n",
      "both existsed: 钱爸爸;深圳市钱爸爸电子商务有限公司\n",
      "both existsed: 深圳市钱爸爸电子商务有限公司;钱爸爸\n",
      "both existsed: 上海夸客金融（才米公社）;才米公社\n",
      "both existsed: 才米公社;上海夸客金融（才米公社）\n",
      "both existsed: 成都易捷金融外包公司;成都易捷金融\n",
      "both existsed: 成都易捷金融;成都易捷金融外包公司\n",
      "both existsed: 北京资易贷金融信息服务有限公司（简称小资钱包）;小资钱包\n",
      "both existsed: 小资钱包;北京资易贷金融信息服务有限公司（简称小资钱包）\n",
      "both existsed: 资易贷(小资钱包）;小资钱包\n",
      "both existsed: 小资钱包;资易贷(小资钱包）\n",
      "both existsed: 米袋360;米袋\n",
      "both existsed: 米袋;米袋360\n",
      "both existsed: 红岭创投;红岭创投电子商务股份有限公司\n",
      "both existsed: 红岭创投电子商务股份有限公司;红岭创投\n",
      "both existsed: 玖富万卡;玖富\n",
      "both existsed: 玖富;玖富万卡\n",
      "both existsed: 美信资产;深圳市美信资产管理公司\n",
      "both existsed: 深圳市美信资产管理公司;美信资产\n",
      "both existsed:  资易贷(小资钱包）;小资钱包\n",
      "both existsed: 小资钱包; 资易贷(小资钱包）\n",
      "both existsed: 钱爸爸;深圳市钱爸爸电子商务有限公司\n",
      "both existsed: 深圳市钱爸爸电子商务有限公司;钱爸爸\n",
      "both existsed: 帅歌家居;济南帅歌家居购物广场有限公司\n",
      "both existsed: 济南帅歌家居购物广场有限公司;帅歌家居\n",
      "both existsed: 北京银行西单支行;北京银行\n",
      "both existsed: 北京银行;北京银行西单支行\n",
      "both existsed: 北京正聚源;正聚源\n",
      "both existsed: 正聚源;北京正聚源\n",
      "both existsed: 北京资易贷金融信息服务有限公司（简称小资钱包）;小资钱包\n",
      "both existsed: 小资钱包;北京资易贷金融信息服务有限公司（简称小资钱包）\n",
      "both existsed: 鼎治泰达;鼎治泰达财富（北京）金融服务外包有限公司\n",
      "both existsed: 鼎治泰达财富（北京）金融服务外包有限公司;鼎治泰达\n",
      "both existsed: 杭州英海互联网科技有限公司（银海金服）;杭州英海互联网科技有限公司\n",
      "both existsed: 杭州英海互联网科技有限公司;杭州英海互联网科技有限公司（银海金服）\n",
      "both existsed: 北京资易贷金融信息服务有限公司（简称小资钱包）;小资钱包\n",
      "both existsed: 小资钱包;北京资易贷金融信息服务有限公司（简称小资钱包）\n",
      "both existsed: 红岭创投;红岭创投电子商务股份有限公司\n",
      "both existsed: 红岭创投电子商务股份有限公司;红岭创投\n"
     ]
    }
   ],
   "source": [
    "#去重：把更短的去掉\n",
    "import numpy as np\n",
    "def remove_short_entity_by_long(entity_str,both_existed_log):\n",
    "    \"\"\"\n",
    "    除去key_entity中同一实体的较短名称\n",
    "    :param entity_str:\n",
    "    :return:\n",
    "    \"\"\"\n",
    "    if not isinstance(entity_str, str):\n",
    "        return entity_str\n",
    "    entities = entity_str.split(';')\n",
    "    states = np.ones(len(entities))\n",
    "    for i, e in enumerate(entities):\n",
    "        for p in entities:\n",
    "            if e in p and len(e) < len(p):\n",
    "                if e in both_existed_log:\n",
    "                    print('not removed %s by %s cause in both_existed_log'%(e,p))\n",
    "                    continue\n",
    "                print('removed %s by %s'%(e,p))\n",
    "                states[i] = 0\n",
    "    rs = []\n",
    "    for i, e in enumerate(entities):\n",
    "        if states[i] == 1:\n",
    "            rs.append(e)\n",
    "    rs = ';'.join(rs)\n",
    "    return rs\n",
    "def remove_short_entity_by_simple_long(entity_str):\n",
    "    \"\"\"\n",
    "    除去key_entity中同一实体的较短名称\n",
    "    :param entity_str:\n",
    "    :return:\n",
    "    \"\"\"\n",
    "    if not isinstance(entity_str, str):\n",
    "        return entity_str\n",
    "    entities = entity_str.split(';')\n",
    "    states = np.ones(len(entities))\n",
    "    for i, e in enumerate(entities):\n",
    "        for p in entities:\n",
    "            if e in p and len(e) < len(p):\n",
    "                print('removed %s by %s'%(e,p))\n",
    "                states[i] = 0\n",
    "    rs = []\n",
    "    for i, e in enumerate(entities):\n",
    "        if states[i] == 1:\n",
    "            rs.append(e)\n",
    "    rs = ';'.join(rs)\n",
    "    return rs\n",
    "def get_trans_map():\n",
    "    from data_utils.basic_data import load_basic_dataset\n",
    "    both_existed_log = ''\n",
    "    train_df = load_basic_dataset('train')\n",
    "    srcs = train_df['entity'].map(lambda x :list(str(x).split(';')))\n",
    "    dests =  train_df['key_entity'].map(lambda x :list(str(x).split(';')))\n",
    "    trans_map = {}\n",
    "    for srcs,dests in list(zip(srcs,dests)):\n",
    "        for src in srcs:\n",
    "            if src == '':\n",
    "                continue\n",
    "            for e in srcs:\n",
    "                if e== '':\n",
    "                    continue\n",
    "                if (src in e or e in src) and e!=src:\n",
    "                    if src in dests:\n",
    "                        trans_map[src+'-'+e] = src\n",
    "                        trans_map[e+'-'+src] = src\n",
    "                    if e in dests:\n",
    "                        trans_map[src+'-'+e] = e\n",
    "                        trans_map[e+'-'+src] = e\n",
    "                    if src in dests and e in dests:\n",
    "                        trans_map[src+'-'+e] = e+';'+src\n",
    "                        trans_map[e+'-'+src] = e+';'+src\n",
    "                        both_existed_log +=  e+';'+src\n",
    "                        print('both existsed:',e+';'+src)\n",
    "    return trans_map,both_existed_log\n",
    "def trans_keys(trans_map,entity_str):\n",
    "    if not isinstance(entity_str,str):\n",
    "        return entity_str\n",
    "    es = list(filter(lambda x:str(x).strip()!='',entity_str.split(';')))\n",
    "    rs = set()\n",
    "    for e in es:\n",
    "        finded = False\n",
    "        for y in es:\n",
    "            if e+'-'+y in trans_map and e!=y:\n",
    "                rs.add(trans_map[e+'-'+y])\n",
    "                finded = True\n",
    "        if not finded:\n",
    "            rs.add(e)\n",
    "    if len(rs) > 0:\n",
    "        rs = ';'.join(list(rs))\n",
    "    else:\n",
    "        rs = np.nan\n",
    "    return rs\n",
    "trans_map,both_existed_log = get_trans_map()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "removed 米咖 by 米咖网\n",
      "not removed 资易贷 by 资易贷（北京）金融服务有限公司 cause in both_existed_log\n",
      "removed 宜贷网 by 上海宜贷网\n",
      "removed 随手记 by 随手记钱包\n",
      "removed 海钜信达 by 深圳市海钜信达投资发展有限公司\n",
      "removed 宜贷网 by ?宜贷网\n",
      "removed 天下投 by 深圳市富通天下投资管理有限公司\n",
      "removed 富通天下 by 深圳市富通天下投资管理有限公司\n",
      "removed 深圳市富通 by 深圳市富通天下投资管理有限公司\n",
      "removed 两只老虎 by 两只老虎理财\n",
      "removed 老虎理财 by 两只老虎理财\n",
      "removed 陆金所 by 西部陆金所\n",
      "removed 小额贷 by 小额贷款有限公司\n",
      "removed 小额贷 by 广州市恒隆小额贷款有限公司\n",
      "removed 小额贷 by 恒隆小额贷款\n",
      "removed 小额贷款有限公司 by 广州市恒隆小额贷款有限公司\n",
      "removed 恒隆小额贷款 by 广州市恒隆小额贷款有限公司\n",
      "removed 宜贷网 by 宜贷网（原易贷网）\n",
      "removed 易贷网 by 宜贷网（原易贷网）\n",
      "not removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司 cause in both_existed_log\n",
      "removed 无忧借条 by ????无忧借条\n",
      "removed 嘉盛 by 嘉盛国际\n",
      "removed 雪橙 by 雪橙金服\n",
      "removed 智融财富 by 深圳市智融财富电商投资有限公司\n",
      "removed 高盛国际 by gs-forex高盛国际\n",
      "removed 山东海倍电子商务 by 山东海倍电子商务股份有限公司\n",
      "removed 国润 by 江西国润\n",
      "removed 随行付 by 随行付支付\n",
      "removed 随行付 by 随行付支付有限公司山西分公司\n",
      "removed 随行付支付 by 随行付支付有限公司山西分公司\n",
      "removed 粤融泰富 by 广东粤融泰富网络信息服务有限公司\n",
      "removed 宜贷网 by 上海宜贷网\n",
      "removed 天合 by 天合联盟\n",
      "removed 天合 by 安徽天合联盟科技有限公司\n",
      "removed 天合联盟 by 安徽天合联盟科技有限公司\n",
      "not removed 昆明泛亚有色 by 昆明泛亚有色金属交易所股份有限公司 cause in both_existed_log\n",
      "removed 北京华澳翼时代 by 北京华澳翼时代信息技术有限责任公司\n",
      "removed 北京华澳融信 by 北京华澳融信国际投资管理咨询有限公司\n",
      "not removed 渤海创投 by 渤海创投集团通 cause in both_existed_log\n",
      "removed 云财富 by 外滩云财富\n",
      "not removed 易贷金融 by  (北京)资易贷金融信息服务有限公司 cause in both_existed_log\n",
      "not removed 资易贷 by 资易贷（北京）金融服务有限公司 cause in both_existed_log\n",
      "removed 易商通 by 北京易商通科技有限公司\n",
      "removed 红太阳 by 湖南红太阳电源新材料股份有限公司\n",
      "removed 深圳光彩 by 深圳光彩投资控股集团有限公司\n",
      "not removed 壹佰金融 by 深圳壹佰金融 cause in both_existed_log\n",
      "removed 和耕传承基金 by 和耕传承基金销售有限公司控股\n",
      "not removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司 cause in both_existed_log\n",
      "removed 宜信 by 宜信惠民\n",
      "removed 宜信 by 宜信普惠\n",
      "removed 瑞波 by 瑞波币\n",
      "removed 滴水贷 by ????滴水贷\n",
      "removed 翱晟投资 by 台州翱晟投资公司\n",
      "removed 深圳高新 by 深圳高新盛\n",
      "removed 高新盛 by 深圳高新盛\n",
      "removed 宜贷网 by 上海宜贷网\n",
      "removed 麒麟金融 by 麒麟金融集团有限公司\n",
      "removed 天天投 by 天天投金融\n",
      "removed 麒麟金融 by 麒麟金融集团有限公司\n",
      "removed 华金融 by 高仕华金融\n",
      "removed 汇鑫小额贷款 by 汇鑫小额贷款有限公司\n",
      "removed 联璧 by 联璧金融\n",
      "not removed 小资钱包 by 北京资易贷金融信息服务有限公司（简称小资钱包） cause in both_existed_log\n",
      "removed 麒麟金融 by 麒麟金融集团有限公司\n",
      "removed 宜贷网 by ????宜贷网\n",
      "removed 深圳高新 by 深圳高新盛创投电子商务有限公司\n",
      "removed 高新盛 by 深圳高新盛创投电子商务有限公司\n",
      "removed 齐鲁商品 by 齐鲁商品交易中心\n",
      "not removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司 cause in both_existed_log\n",
      "removed 亚太投资 by 北京亚太投资\n",
      "removed 汇聚财富 by 上海汇聚财富\n",
      "not removed 渤海创投 by ?渤海创投子公司智慧蜂巢 cause in both_existed_log\n",
      "removed 宜贷网 by ????宜贷网\n",
      "removed 小额贷款有限公司 by 中合华惠农村小额贷款有限公司\n",
      "removed 宜贷网 by 上海宜贷网\n",
      "removed 宜贷网 by 成都宜贷网\n",
      "removed 御顺金融 by 成都御顺金融贷款公司\n",
      "not removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司 cause in both_existed_log\n",
      "removed 盛付通 by 上海盛付通电子支付服务有限公司陕西分公司\n",
      "removed 宜贷网 by 上海宜贷网金融信息公司\n",
      "removed 浙商银行 by 浙商银行直销银行\n",
      "removed 恒宇 by 恒宇天泽\n",
      "removed 圣盈信 by 圣盈信CIFS\n",
      "removed 零钱罐 by 零钱罐APP\n",
      "removed 小额贷款有限公司 by 万源农村小额贷款有限公司与沈秋云\n",
      "removed 广西弘尚节节贷集团 by 广西弘尚节节贷集团(节节资本)\n",
      "removed 节节贷 by 广西弘尚节节贷集团\n",
      "removed 节节贷 by 广西弘尚节节贷集团(节节资本)\n",
      "not removed 资易贷 by 资易贷北京金融信息服务有限公 cause in both_existed_log\n",
      "removed 宜贷网 by ????宜贷网\n",
      "removed 点融 by 点融网\n",
      "removed 中南大宗 by 中南大宗商品电子商务有限公司\n",
      "removed 智云 by 智云金融\n",
      "not removed 易贷金融 by  (北京)资易贷金融信息服务有限公司 cause in both_existed_log\n",
      "not removed 玖富 by 玖富?投诉量最多 cause in both_existed_log\n",
      "not removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司 cause in both_existed_log\n",
      "removed fx by fx福克斯\n",
      "removed fx by onefx\n",
      "removed 麒麟金融 by 麒麟金融集团有限公司\n",
      "removed 米融 by 易米融\n",
      "removed 中吴财富 by 上海中吴财富投资管理集团有限公司\n",
      "removed 节节贷 by 广西弘尚节节贷网络信息服务集团有限公司\n",
      "removed 兴业财富 by 北方兴业财富\n",
      "not removed 小资钱包 by ????小资钱包 cause in both_existed_log\n",
      "not removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司 cause in both_existed_log\n",
      "not removed 昆明泛亚有色 by 昆明泛亚有色金属交易所股份有限公司 cause in both_existed_log\n",
      "removed 沃德 by 沃德斯国际\n",
      "removed 蜜蜂 by 蜜蜂财富\n",
      "removed 宜贷网 by ????宜贷网\n",
      "removed 中银消费金融 by 中银消费金融有限公司\n",
      "removed 钱宝 by 钱宝财\n",
      "removed 房融 by 房融所\n",
      "removed 随行付 by 随行付支付\n",
      "removed 随行付 by 随行付支付有限公司\n",
      "removed 随行付支付 by 随行付支付有限公司\n",
      "removed 宜贷网 by ????宜贷网\n",
      "not removed 资易贷 by 资易贷(北京）金融信息有限公司公司 cause in both_existed_log\n",
      "removed 冠群驰骋 by 冠群驰骋商务信息咨询（天津）有限公司\n",
      "not removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司 cause in both_existed_log\n",
      "removed 优宝 by 优宝汇\n",
      "removed 青岛九州商品交易中心 by 青岛九州商品交易中心有限公司\n",
      "removed 宜贷网 by ????宜贷网\n",
      "removed 海贷 by 海贷金服\n",
      "removed 海贷 by 海贷金服体验金\n",
      "removed 海贷金服 by 海贷金服体验金\n",
      "removed 宜贷网 by 上海易贷网金融信息公司（宜贷网）\n",
      "removed 钱宝 by 钱宝财\n",
      "removed 宜贷网 by 上海宜贷网\n",
      "removed 世纪贷 by 世纪贷互联网金融服务有限公司\n",
      "removed 海象理财 by 北京海象理财\n",
      "removed 银通投资 by 中润银通投资北京有限公司\n",
      "removed 华夏信财 by 华夏信财信息咨询（上海）有限公司芜湖分公司\n",
      "removed 宜贷网 by 上海宜贷网\n",
      "not removed 鼎治泰达 by 鼎治泰达财富（北京）金融服务外包有限公司 cause in both_existed_log\n",
      "not removed 小资钱包 by 北京资易贷金融信息服务有限公司（简称小资钱包） cause in both_existed_log\n",
      "removed 仁和融兴 by 青岛仁和融兴投资有限公司\n",
      "removed 海象理财 by 北京海象理财\n",
      "not removed 小资钱包 by 北京资易贷金融信息服务有限公司（简称小资钱包）  cause in both_existed_log\n",
      "removed 商银信支付 by 商银信支付服务有限公司\n",
      "not removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司 cause in both_existed_log\n",
      "not removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司 cause in both_existed_log\n",
      "removed 钱海湾 by 钱海湾金融\n",
      "removed 钱海湾 by 钱海湾金融公司\n",
      "removed 钱海湾金融 by 钱海湾金融公司\n",
      "removed 大宗商品交易 by 河北滨海大宗商品交易市场\n",
      "removed 大宗商品交易 by 河北滨海大宗商品交易市场服务有限公司\n",
      "removed 河北滨海大宗商品交易市场 by 河北滨海大宗商品交易市场服务有限公司\n",
      "removed 优库速购 by 深圳优库速购\n",
      "removed igofx by igofx平台\n",
      "removed 市大时代 by 深圳市大时代资产管理有限公司\n",
      "removed 时贷 by 大时贷\n",
      "not removed 小资钱包 by 北京资易贷金融信息服务有限公司（简称小资钱包） cause in both_existed_log\n",
      "not removed 易贷金融 by  (北京)资易贷金融信息服务有限公司 cause in both_existed_log\n",
      "not removed 小资钱包 by 北京资易贷金融信息服务有限公司（简称小资钱包） cause in both_existed_log\n",
      "removed 信e贷 by 久信e贷\n",
      "removed 中赢投 by 中赢投资\n",
      "removed 玖财 by 玖财通\n",
      "removed 懒财主 by 前海懒财主金融\n",
      "removed 懒财主 by 海懒财主金融信息服务（深圳）有限公司\n",
      "removed 和信 by 资和信\n",
      "removed 宜贷网 by 宜贷网（原易贷网）\n",
      "removed 易贷网 by 宜贷网（原易贷网）\n",
      "not removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司 cause in both_existed_log\n",
      "removed 米融 by 易米融\n",
      "removed 日融财富 by 宁波日融财富投资管理有限公司\n",
      "removed 蜜蜂 by 蜜蜂财富\n",
      "not removed 小资钱包 by 资易贷（小资钱包） cause in both_existed_log\n",
      "not removed 资易贷 by 资易贷（小资钱包） cause in both_existed_log\n",
      "not removed 小资钱包 by 小资钱包公司(资易贷平台) cause in both_existed_log\n",
      "not removed 资易贷 by 小资钱包公司(资易贷平台) cause in both_existed_log\n",
      "removed 以太坊 by 以太坊ETH\n",
      "removed 上海易贷网 by 上海易贷网金融信息服务有限公司\n",
      "removed 上海文化产权交易所 by 上海文化产权交易所股份有限公司\n",
      "removed 中子星投资 by 中子星投资有限公司\n",
      "removed 星投资 by 中子星投资\n",
      "removed 星投资 by 中子星投资有限公司\n",
      "removed 36氪 by 36氪股权众筹\n",
      "not removed 小资钱包 by 北京资易贷金融信息服务有限公司（简称小资钱包） cause in both_existed_log\n",
      "removed 联金所 by 联金所康\n",
      "removed 金易融 by 金易融（北京）网络科技有限公司\n",
      "removed 钱宝 by 钱宝财\n",
      "removed 信和大金融 by 传信和大金融\n",
      "removed 创赢投资 by 上海宝银创赢投资管理有限公司\n",
      "removed 宝银创赢 by 上海宝银创赢投资管理有限公司\n",
      "removed 凯福德 by KFD凯福德\n",
      "removed 瑞财 by 恒瑞财富\n",
      "removed 中海投 by 上海中海投资产管理有限公司\n",
      "removed 中海投 by 中海投资\n",
      "removed 中海投资 by 上海中海投资产管理有限公司\n",
      "not removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司 cause in both_existed_log\n",
      "not removed 易贷金融 by （北京）资易贷金融信息服务有限公司 cause in both_existed_log\n",
      "removed 唐小僧 by 唐小僧之后\n",
      "removed 宜贷网 by ????宜贷网\n",
      "removed 北京华澳融信 by 北京华澳融信国际投资管理咨询有限公司\n",
      "removed 米融 by 易米融\n",
      "removed 长征财富 by 长征财富资产管理有限公司宝应支公司\n",
      "removed 老虎金融 by 老虎金融信息服务（北京）有限公司\n",
      "removed 冠群驰骋 by 冠群驰骋投资关联(北京)有限公司\n",
      "removed 冠群驰骋 by 冠群驰骋投资管理(北京)有限公司\n",
      "not removed 小资钱包 by  资易贷(小资钱包） cause in both_existed_log\n",
      "removed 小额贷款有限公司 by 金久农村小额贷款有限公司\n",
      "removed 银网贷 by 超银网贷\n",
      "removed tbc by tbc（海湾资本）澳大利亚asic\n",
      "removed 翱晟投资 by 台州翱晟投资公司\n",
      "removed 聚财猫 by ????聚财猫\n",
      "not removed 小资钱包 by 北京资易贷公司（小资钱包) cause in both_existed_log\n",
      "not removed 资易贷 by 北京资易贷公司（小资钱包) cause in both_existed_log\n",
      "removed 仁和融兴 by 青岛仁和融兴投资有限公司\n",
      "removed 日融财富 by 宁波日融财富投资管理有限公司\n",
      "removed 冠e通 by 冠e通平台\n",
      "not removed 小资钱包 by 北京资易贷金融信息服务有限公司（简称小资钱包） cause in both_existed_log\n",
      "removed 一号家居网 by 一号家居网装饰公司\n",
      "removed 易商通 by 北京易商通科技有限公司\n",
      "removed 麒麟金融 by 麒麟金融集团有限公司\n",
      "removed 山东海倍电子商务 by 山东海倍电子商务股份有限公司\n",
      "removed 简贷 by 易简贷\n",
      "removed 汇金方格 by 汇金方格（北京）投资管理有限公司\n",
      "removed 融通资产 by 北京圆融通资产管理有限公司\n",
      "not removed 资易贷 by 海淀资易贷平台 cause in both_existed_log\n",
      "removed 惠金服 by 城惠金服\n",
      "not removed 小资钱包 by 北京资易贷金融信息服务有限公司（简称小资钱包） cause in both_existed_log\n",
      "removed 乐贷 by 网乐贷\n",
      "removed 易商通 by 北京易商通科技有限公司\n",
      "removed 东方投 by 深圳市誉东方投资管理平台\n",
      "removed 东方投 by 誉东方投资管理\n",
      "removed 誉东方投资管理 by 深圳市誉东方投资管理平台\n",
      "removed 宜贷网 by 上海宜贷网\n",
      "removed 理财帝 by 理财帝国\n",
      "removed 冠群驰骋 by ????冠群驰骋\n",
      "removed 大宗商品交易 by 河北滨海大宗商品交易市场\n",
      "removed 时贷 by 森昊好时贷\n",
      "removed 贷联盟 by 新贷联盟\n",
      "removed 宜贷网 by 上海宜贷网\n",
      "removed 澳瑞克 by OracleFX澳瑞克\n",
      "removed 新余铭沃 by 新余铭沃投资管理中心\n",
      "removed 赛伯乐绿科 by 深圳赛伯乐绿科投资管理有限公司\n",
      "removed 重庆赛伯乐盈科 by 重庆赛伯乐盈科股权投资基金管理有限公司\n",
      "removed 宜贷网 by 上海宜贷网\n",
      "removed 中吴财富 by 上海中吴财富投资管理集团有限公司\n",
      "not removed 资易贷 by 资易贷（北京）金融信息服务公司 cause in both_existed_log\n",
      "removed 汇聚财富 by 上海汇聚财富投资\n",
      "not removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司 cause in both_existed_log\n",
      "not removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司 cause in both_existed_log\n",
      "removed 联璧 by 联璧金融\n",
      "removed 宜贷网 by ????宜贷网\n",
      "not removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司 cause in both_existed_log\n",
      "removed 宜贷网 by ????宜贷网\n",
      "not removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司 cause in both_existed_log\n",
      "removed 渤海商品交易 by 天津渤海商品交易所\n",
      "removed 富民投资 by 富民投资网\n",
      "removed 银通投资 by 中润银通投资(北京)有限公司\n",
      "removed 余盆网 by 北京华澳融信（余盆网）\n",
      "removed 北京华澳融信 by 北京华澳融信（余盆网）\n",
      "removed 三农金服 by 深圳三农金服\n",
      "removed 宜贷网 by 上海宜贷网\n",
      "not removed 资易贷 by 资易贷（北京）金融信息服务有限公司旗 cause in both_existed_log\n",
      "not removed 钱包 by 钱包网 cause in both_existed_log\n",
      "removed 宜贷网 by ????宜贷网\n",
      "not removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司 cause in both_existed_log\n",
      "removed 卡宝 by 卡宝典\n",
      "not removed 玖富 by 北京玖富集团 cause in both_existed_log\n",
      "not removed 小资 by 小资钱包 cause in both_existed_log\n",
      "removed 嘉盛 by 嘉盛国际\n",
      "removed 时贷 by 大时贷\n",
      "removed 钱宝 by 钱宝财\n",
      "removed 渤海商品交易 by 天津渤海商品交易所\n",
      "removed 渤海商品交易 by 渤海商品交易所\n",
      "removed 渤海商品交易所 by 天津渤海商品交易所\n",
      "removed 中银 by 中银消费金融\n",
      "removed 中银 by 中银消费金融有限公司\n",
      "removed 中银消费金融 by 中银消费金融有限公司\n",
      "removed 富民投资 by 富民投资网\n",
      "not removed 北京银行 by 北京银行西单支行 cause in both_existed_log\n",
      "removed 宜贷网 by ?宜贷网\n"
     ]
    }
   ],
   "source": [
    "rs_df['key_entity'] = rs_df['key_entity'].map(lambda x:remove_short_entity_by_long(x,both_existed_log))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "sub_nan = rs_df[rs_df['negative']==1]\n",
    "sub_nan = sub_nan[sub_nan['key_entity'].map(lambda x:isinstance(x,float))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>negative</th>\n",
       "      <th>key_entity</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>135</td>\n",
       "      <td>06cf507c</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>146</td>\n",
       "      <td>077a7f27</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>244</td>\n",
       "      <td>0bf91989</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>588</td>\n",
       "      <td>1d110b8c</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>724</td>\n",
       "      <td>23acf103</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>848</td>\n",
       "      <td>2aa57004</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>867</td>\n",
       "      <td>2bd24932</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>892</td>\n",
       "      <td>2d2c9223</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>985</td>\n",
       "      <td>334437be</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1016</td>\n",
       "      <td>3537df38</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1101</td>\n",
       "      <td>396230d9</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1291</td>\n",
       "      <td>4383d929</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1479</td>\n",
       "      <td>4e3cda19</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1549</td>\n",
       "      <td>515b1a3c</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1769</td>\n",
       "      <td>5cbe0c83</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1830</td>\n",
       "      <td>60900ec3</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1915</td>\n",
       "      <td>647b7e3a</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2295</td>\n",
       "      <td>763c0846</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2395</td>\n",
       "      <td>7a6c6068</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2476</td>\n",
       "      <td>7ecfd22a</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2511</td>\n",
       "      <td>801fa398</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2629</td>\n",
       "      <td>8675ad50</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2819</td>\n",
       "      <td>900f229a</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2897</td>\n",
       "      <td>94b85e30</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2934</td>\n",
       "      <td>97068a46</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2946</td>\n",
       "      <td>97b60f42</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3006</td>\n",
       "      <td>9ada02f2</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3132</td>\n",
       "      <td>a09c6ef4</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3252</td>\n",
       "      <td>a757818f</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3326</td>\n",
       "      <td>ab2ec010</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3659</td>\n",
       "      <td>bc9b5c81</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3821</td>\n",
       "      <td>c5dc281e</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4023</td>\n",
       "      <td>d00443e9</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4244</td>\n",
       "      <td>dbb33b08</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4396</td>\n",
       "      <td>e355afe7</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4408</td>\n",
       "      <td>e3c0d569</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4440</td>\n",
       "      <td>e55a3377</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4519</td>\n",
       "      <td>e971773f</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4526</td>\n",
       "      <td>e9abc6b0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4758</td>\n",
       "      <td>f4c60325</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4803</td>\n",
       "      <td>f6a4eda1</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4856</td>\n",
       "      <td>f93cbbc2</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4992</td>\n",
       "      <td>ff9315ec</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            id  negative key_entity\n",
       "135   06cf507c         1        NaN\n",
       "146   077a7f27         1        NaN\n",
       "244   0bf91989         1        NaN\n",
       "588   1d110b8c         1        NaN\n",
       "724   23acf103         1        NaN\n",
       "848   2aa57004         1        NaN\n",
       "867   2bd24932         1        NaN\n",
       "892   2d2c9223         1        NaN\n",
       "985   334437be         1        NaN\n",
       "1016  3537df38         1        NaN\n",
       "1101  396230d9         1        NaN\n",
       "1291  4383d929         1        NaN\n",
       "1479  4e3cda19         1        NaN\n",
       "1549  515b1a3c         1        NaN\n",
       "1769  5cbe0c83         1        NaN\n",
       "1830  60900ec3         1        NaN\n",
       "1915  647b7e3a         1        NaN\n",
       "2295  763c0846         1        NaN\n",
       "2395  7a6c6068         1        NaN\n",
       "2476  7ecfd22a         1        NaN\n",
       "2511  801fa398         1        NaN\n",
       "2629  8675ad50         1        NaN\n",
       "2819  900f229a         1        NaN\n",
       "2897  94b85e30         1        NaN\n",
       "2934  97068a46         1        NaN\n",
       "2946  97b60f42         1        NaN\n",
       "3006  9ada02f2         1        NaN\n",
       "3132  a09c6ef4         1        NaN\n",
       "3252  a757818f         1        NaN\n",
       "3326  ab2ec010         1        NaN\n",
       "3659  bc9b5c81         1        NaN\n",
       "3821  c5dc281e         1        NaN\n",
       "4023  d00443e9         1        NaN\n",
       "4244  dbb33b08         1        NaN\n",
       "4396  e355afe7         1        NaN\n",
       "4408  e3c0d569         1        NaN\n",
       "4440  e55a3377         1        NaN\n",
       "4519  e971773f         1        NaN\n",
       "4526  e9abc6b0         1        NaN\n",
       "4758  f4c60325         1        NaN\n",
       "4803  f6a4eda1         1        NaN\n",
       "4856  f93cbbc2         1        NaN\n",
       "4992  ff9315ec         1        NaN"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sub_nan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "multi_choice_rs = pd.read_csv('evaluation/tmp/multi_choice_cross1-9_1024.csv')\n",
    "for id,negative,key_entity in sub_nan[['id','negative','key_entity']].values:\n",
    "    rs_df.loc[rs_df['id']==id,'key_entity'] =  multi_choice_rs.loc[multi_choice_rs['id']==id,'key_entity'].values[0]\n",
    "    rs_df.loc[rs_df['id']==id,'negative'] = int(multi_choice_rs.loc[multi_choice_rs['id']==id,'negative'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>negative</th>\n",
       "      <th>key_entity</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>135</td>\n",
       "      <td>06cf507c</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>146</td>\n",
       "      <td>077a7f27</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>244</td>\n",
       "      <td>0bf91989</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>588</td>\n",
       "      <td>1d110b8c</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>724</td>\n",
       "      <td>23acf103</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>848</td>\n",
       "      <td>2aa57004</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>867</td>\n",
       "      <td>2bd24932</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>892</td>\n",
       "      <td>2d2c9223</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>985</td>\n",
       "      <td>334437be</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1016</td>\n",
       "      <td>3537df38</td>\n",
       "      <td>1</td>\n",
       "      <td>中信证券</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1101</td>\n",
       "      <td>396230d9</td>\n",
       "      <td>1</td>\n",
       "      <td>拍拍贷;网利宝</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1291</td>\n",
       "      <td>4383d929</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1479</td>\n",
       "      <td>4e3cda19</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1549</td>\n",
       "      <td>515b1a3c</td>\n",
       "      <td>1</td>\n",
       "      <td>百度金融</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1769</td>\n",
       "      <td>5cbe0c83</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1830</td>\n",
       "      <td>60900ec3</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1915</td>\n",
       "      <td>647b7e3a</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2295</td>\n",
       "      <td>763c0846</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2395</td>\n",
       "      <td>7a6c6068</td>\n",
       "      <td>1</td>\n",
       "      <td>玖富万卡</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2476</td>\n",
       "      <td>7ecfd22a</td>\n",
       "      <td>1</td>\n",
       "      <td>好想贷</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2511</td>\n",
       "      <td>801fa398</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2629</td>\n",
       "      <td>8675ad50</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2819</td>\n",
       "      <td>900f229a</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2897</td>\n",
       "      <td>94b85e30</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2934</td>\n",
       "      <td>97068a46</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2946</td>\n",
       "      <td>97b60f42</td>\n",
       "      <td>1</td>\n",
       "      <td>无忧车贷</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3006</td>\n",
       "      <td>9ada02f2</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3132</td>\n",
       "      <td>a09c6ef4</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3252</td>\n",
       "      <td>a757818f</td>\n",
       "      <td>1</td>\n",
       "      <td>网贷之家</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3326</td>\n",
       "      <td>ab2ec010</td>\n",
       "      <td>1</td>\n",
       "      <td>融360</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3659</td>\n",
       "      <td>bc9b5c81</td>\n",
       "      <td>1</td>\n",
       "      <td>红岭创投</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3821</td>\n",
       "      <td>c5dc281e</td>\n",
       "      <td>1</td>\n",
       "      <td>玖富万卡</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4023</td>\n",
       "      <td>d00443e9</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4244</td>\n",
       "      <td>dbb33b08</td>\n",
       "      <td>1</td>\n",
       "      <td>以太坊</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4396</td>\n",
       "      <td>e355afe7</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4408</td>\n",
       "      <td>e3c0d569</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4440</td>\n",
       "      <td>e55a3377</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4519</td>\n",
       "      <td>e971773f</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4526</td>\n",
       "      <td>e9abc6b0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4758</td>\n",
       "      <td>f4c60325</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4803</td>\n",
       "      <td>f6a4eda1</td>\n",
       "      <td>1</td>\n",
       "      <td>长沙银行</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4856</td>\n",
       "      <td>f93cbbc2</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4992</td>\n",
       "      <td>ff9315ec</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            id  negative key_entity\n",
       "135   06cf507c         0        NaN\n",
       "146   077a7f27         1        NaN\n",
       "244   0bf91989         0        NaN\n",
       "588   1d110b8c         0        NaN\n",
       "724   23acf103         1        NaN\n",
       "848   2aa57004         1        NaN\n",
       "867   2bd24932         1        NaN\n",
       "892   2d2c9223         0        NaN\n",
       "985   334437be         1        NaN\n",
       "1016  3537df38         1       中信证券\n",
       "1101  396230d9         1    拍拍贷;网利宝\n",
       "1291  4383d929         1        NaN\n",
       "1479  4e3cda19         0        NaN\n",
       "1549  515b1a3c         1       百度金融\n",
       "1769  5cbe0c83         0        NaN\n",
       "1830  60900ec3         1        NaN\n",
       "1915  647b7e3a         1        NaN\n",
       "2295  763c0846         0        NaN\n",
       "2395  7a6c6068         1       玖富万卡\n",
       "2476  7ecfd22a         1        好想贷\n",
       "2511  801fa398         1        NaN\n",
       "2629  8675ad50         0        NaN\n",
       "2819  900f229a         1        NaN\n",
       "2897  94b85e30         0        NaN\n",
       "2934  97068a46         0        NaN\n",
       "2946  97b60f42         1       无忧车贷\n",
       "3006  9ada02f2         0        NaN\n",
       "3132  a09c6ef4         0        NaN\n",
       "3252  a757818f         1       网贷之家\n",
       "3326  ab2ec010         1       融360\n",
       "3659  bc9b5c81         1       红岭创投\n",
       "3821  c5dc281e         1       玖富万卡\n",
       "4023  d00443e9         0        NaN\n",
       "4244  dbb33b08         1        以太坊\n",
       "4396  e355afe7         0        NaN\n",
       "4408  e3c0d569         0        NaN\n",
       "4440  e55a3377         0        NaN\n",
       "4519  e971773f         0        NaN\n",
       "4526  e9abc6b0         0        NaN\n",
       "4758  f4c60325         1        NaN\n",
       "4803  f6a4eda1         1       长沙银行\n",
       "4856  f93cbbc2         1        NaN\n",
       "4992  ff9315ec         1        NaN"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rs_df[rs_df['id'].isin(sub_nan['id'])]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "rs_df.to_csv('tmp/stack_removenan_1.3_testgoodremove.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "removed 资易贷 by 资易贷（北京）金融服务有限公司\n",
      "removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司\n",
      "removed 昆明泛亚有色 by 昆明泛亚有色金属交易所股份有限公司\n",
      "removed 渤海创投 by 渤海创投集团通\n",
      "removed 易贷金融 by  (北京)资易贷金融信息服务有限公司\n",
      "removed 资易贷 by 资易贷（北京）金融服务有限公司\n",
      "removed 壹佰金融 by 深圳壹佰金融\n",
      "removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司\n",
      "removed 小资钱包 by 北京资易贷金融信息服务有限公司（简称小资钱包）\n",
      "removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司\n",
      "removed 渤海创投 by ?渤海创投子公司智慧蜂巢\n",
      "removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司\n",
      "removed 资易贷 by 资易贷北京金融信息服务有限公\n",
      "removed 易贷金融 by  (北京)资易贷金融信息服务有限公司\n",
      "removed 玖富 by 玖富?投诉量最多\n",
      "removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司\n",
      "removed 小资钱包 by ????小资钱包\n",
      "removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司\n",
      "removed 昆明泛亚有色 by 昆明泛亚有色金属交易所股份有限公司\n",
      "removed 资易贷 by 资易贷(北京）金融信息有限公司公司\n",
      "removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司\n",
      "removed 鼎治泰达 by 鼎治泰达财富（北京）金融服务外包有限公司\n",
      "removed 小资钱包 by 北京资易贷金融信息服务有限公司（简称小资钱包）\n",
      "removed 小资钱包 by 北京资易贷金融信息服务有限公司（简称小资钱包） \n",
      "removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司\n",
      "removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司\n",
      "removed 小资钱包 by 北京资易贷金融信息服务有限公司（简称小资钱包）\n",
      "removed 易贷金融 by  (北京)资易贷金融信息服务有限公司\n",
      "removed 小资钱包 by 北京资易贷金融信息服务有限公司（简称小资钱包）\n",
      "removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司\n",
      "removed 小资钱包 by 资易贷（小资钱包）\n",
      "removed 资易贷 by 资易贷（小资钱包）\n",
      "removed 小资钱包 by 小资钱包公司(资易贷平台)\n",
      "removed 资易贷 by 小资钱包公司(资易贷平台)\n",
      "removed 小资钱包 by 北京资易贷金融信息服务有限公司（简称小资钱包）\n",
      "removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司\n",
      "removed 易贷金融 by （北京）资易贷金融信息服务有限公司\n",
      "removed 小资钱包 by  资易贷(小资钱包）\n",
      "removed 小资钱包 by 北京资易贷公司（小资钱包)\n",
      "removed 资易贷 by 北京资易贷公司（小资钱包)\n",
      "removed 小资钱包 by 北京资易贷金融信息服务有限公司（简称小资钱包）\n",
      "removed 资易贷 by 海淀资易贷平台\n",
      "removed 小资钱包 by 北京资易贷金融信息服务有限公司（简称小资钱包）\n",
      "removed 资易贷 by 资易贷（北京）金融信息服务公司\n",
      "removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司\n",
      "removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司\n",
      "removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司\n",
      "removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司\n",
      "removed 资易贷 by 资易贷（北京）金融信息服务有限公司旗\n",
      "removed 钱包 by 钱包网\n",
      "removed 钱爸爸 by 深圳市钱爸爸电子商务有限公司\n",
      "removed 玖富 by 北京玖富集团\n",
      "removed 小资 by 小资钱包\n",
      "removed 北京银行 by 北京银行西单支行\n"
     ]
    }
   ],
   "source": [
    "rs_df['key_entity'] = rs_df['key_entity'].map(remove_short_entity_by_simple_long)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "rs_df.to_csv('tmp/stack_removenan_1.4_testsimpleremove.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9567839195979899\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "      Benign       0.97      0.94      0.96       514\n",
      "   Malignant       0.94      0.97      0.96       481\n",
      "\n",
      "    accuracy                           0.96       995\n",
      "   macro avg       0.96      0.96      0.96       995\n",
      "weighted avg       0.96      0.96      0.96       995\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(sgdc.score(X_test_std,y_test))\n",
    "y_result = sgdc.predict(X_test_std)\n",
    "print(classification_report(y_test,y_result,target_names=['Benign','Malignant']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',\n",
       "                       max_depth=None, max_features='auto', max_leaf_nodes=None,\n",
       "                       min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "                       min_samples_leaf=1, min_samples_split=2,\n",
       "                       min_weight_fraction_leaf=0.0, n_estimators=100,\n",
       "                       n_jobs=None, oob_score=False, random_state=None,\n",
       "                       verbose=0, warm_start=False)"
      ]
     },
     "execution_count": 162,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.ensemble import RandomForestClassifier\n",
    " \n",
    "clf = RandomForestClassifier(n_estimators=100)\n",
    "clf.fit(X_train_std, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9517587939698492\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "      Benign       0.96      0.95      0.95       514\n",
      "   Malignant       0.95      0.95      0.95       481\n",
      "\n",
      "    accuracy                           0.95       995\n",
      "   macro avg       0.95      0.95      0.95       995\n",
      "weighted avg       0.95      0.95      0.95       995\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(clf.score(X_test_std,y_test))\n",
    "y_result = clf.predict(X_test_std)\n",
    "print(classification_report(y_test,y_result,target_names=['Benign','Malignant']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9577889447236181\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "      Benign       0.97      0.95      0.96       514\n",
      "   Malignant       0.95      0.97      0.96       481\n",
      "\n",
      "    accuracy                           0.96       995\n",
      "   macro avg       0.96      0.96      0.96       995\n",
      "weighted avg       0.96      0.96      0.96       995\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from sklearn.ensemble import GradientBoostingClassifier\n",
    " \n",
    "clf = GradientBoostingClassifier(n_estimators=200)\n",
    "clf.fit(X_train_std, y_train)\n",
    "print(clf.score(X_test_std,y_test))\n",
    "y_result = clf.predict(X_test_std)\n",
    "print(classification_report(y_test,y_result,target_names=['Benign','Malignant']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9577889447236181\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "      Benign       0.97      0.95      0.96       514\n",
      "   Malignant       0.95      0.97      0.96       481\n",
      "\n",
      "    accuracy                           0.96       995\n",
      "   macro avg       0.96      0.96      0.96       995\n",
      "weighted avg       0.96      0.96      0.96       995\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from sklearn.ensemble import  AdaBoostClassifier\n",
    " \n",
    "clf = AdaBoostClassifier()\n",
    "clf.fit(X_train_std, y_train)\n",
    "print(clf.score(X_test_std,y_test))\n",
    "y_result = clf.predict(X_test_std)\n",
    "print(classification_report(y_test,y_result,target_names=['Benign','Malignant']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
